package com.onec.service.customer.entity.agent;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.onec.service.api.content.AesEntityContent;
import com.onec.service.api.enums.ProductEnum;
import com.onec.service.api.enums.StatusEnum;
import lombok.Data;
import org.hibernate.annotations.ColumnTransformer;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 代理商
 * 渠道信息。
 *
 * @author ONEC
 */
@Data
@Entity
@Table(name = "t_agent_info")
public class AgentInfo implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true)
    private Long id;

    @Column(name = "version", length = 8)
    private Integer version;

    /**
     * 通道编号
     */
    @Column(name = "agent_code", length = 16, unique = true)
    private String agentCode;
    /**
     * 通道名称
     */
    @Column(name = "name", length = 32)
    private String name;

    @Column(name = "product", length = 8)
    @Enumerated(EnumType.STRING)
    private ProductEnum product;

    /**
     * 联系人
     */
    @Column(name = "contacts", length = 32)
    private String contacts;
    /**
     * 联系人
     */
    @ColumnTransformer(
            read = AesEntityContent.AES_DECRYPT_PHONE,
            write = AesEntityContent.AES_ENCRYPT_PHONE
    )
    @Column(name = "phone", length = 128)
    private String phone;
    /**
     * 机构编号
     */
    @Column(name = "no", length = 32)
    private String no;
    /**
     * 创建时间
     */
    @Column(name = "create_time", length = 0)
    @CreatedDate
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm", timezone = "GTM+8")
    private Date createTime;
    /**
     * 变更
     */
    @Column(name = "update_time", length = 0)
    @LastModifiedDate
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm", timezone = "GTM+8")
    private Date updateTime;
    /**
     * 创建者
     */
    @Column(name = "creator", length = 32)
    private String creator;
    /**
     * 产品备注
     */
    @Column(name = "remarks", length = 64)
    private String remarks;
    /**
     * 通道状态
     */
    @Column(name = "status", length = 12)
    @Enumerated(EnumType.STRING)
    private StatusEnum status;


    public AgentInfo() {
    }

    public AgentInfo(Integer version, String agentCode, String name, ProductEnum product, String contacts, String phone,
                     String no, Date createTime, Date updateTime, String creator, String remarks, StatusEnum status) {
        this.version = version;
        this.agentCode = agentCode;
        this.name = name;
        this.product = product;
        this.contacts = contacts;
        this.phone = phone;
        this.no = no;
        this.createTime = createTime;
        this.updateTime = updateTime;
        this.creator = creator;
        this.remarks = remarks;
        this.status = status;
    }


}
